<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
    <script src="../vue-router.js"></script>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <!-- 路由出口 -->
        <router-view></router-view>
        <router-link to="/home">首页</router-link>
        <router-link :to="{name:'find',params:{address:'上海',time:'2.13'}}">发现页</router-link>
        <!-- <router-link to="/find/武汉/2.13">发现页</router-link> -->
        <router-link to="/user?id=1&name=不吃鱼d猫">用户中心</router-link>
    </div>
    <template id="home">
        <div>
            <h1>{{content}}</h1>
        </div>
    </template>
    <template id="find">
        <div>
            <h1>{{content}}</h1>
        <h2>{{$route.params.address}}</h2>
        <h2>{{$route.params.time}}</h2>
        <h2>{{$route.fullPath}}</h2>
        <h2>{{$route.path}}</h2>
        <h2>{{$route.meta}}</h2>
        <h2>{{$route.name}}</h2>
        </div>
    </template>
    <template id="user">
        <div>
            <h1>{{content}}</h1>
            <h2>{{$route.query.name}}</h2>
            <h2>{{$route.query.id}}</h2>
        </div>
    </template>
    <script>
        //定义路由组件
        const Home = {
            template: "#home",
            data() {
                return {
                    content: "我是首页"
                }
            },

        }
        const Find = {
            template: "#find",
            data() {
                return {
                    content: "我是发现页"
                }
            },

        }
        const User = {
            template: "#user",
            data() {
                return {
                    content: "我是个人中心"
                }
            },

        }

        //定义一些路由
        const routers = [{
            path: "/",
            //重定向
            redirect: "/home"
        }, {
            path: '/home',
            component: Home
        }, {
            path: '/find/:address/:time',
            name: 'find',
            component: Find
        }, {
            path: '/user',
            component: User
        }, ]

        const router = new VueRouter({
            routes: routers,
            mode: 'hash'
        })
        const vm = new Vue({
            //挂载路由
            router,
            data: {
                title: "路由传参"
            }
        }).$mount(".app")
    </script>

</body>

</html>